// 全局请求封装
// const base_url = 'http://792509sg45.zicp.fun/';
const base_url = 'http://localhost:8081/';
const timeout = 5000;

export default (params) => {
    let url = params.url;
    let method = params.method || "get";
    let data = params.data || {};
    let header = {
        'Blade-Auth': uni.getStorageSync('token') || '',
        'Content-Type': 'application/json;charset=UTF-8',
        'Authorization': 'Basic c2FiZXI6c2FiZXJfc2VjcmV0',
        'Tenant-Id': uni.getStorageSync('tenantId') || 'xxx',
        ...params.header
    };

    if (method.toLowerCase() === "post") {
        header = {
            ...header,
            'Content-Type': 'application/json'
        };
    }

    return new Promise((resolve, reject) => {
        uni.request({
            url: base_url + url,
            method: method,
            header: header,
            data: data,
            timeout: timeout,
            success(response) {
                resolve(response);
            },
            fail(err) {
                reject(err);
            },
            complete() {
                // 不管成功还是失败都会执行
                uni.hideLoading();
                uni.hideToast();
            }
        });
    });
};